package designer.single;

/**
 * 非同步 懒汉模式
 * Created by tanlee on 2016/4/6.
 */
public class Singleton2 {
    private  static Singleton2 singleton2;

    private Singleton2() {

    }

    public static Singleton2 getInstance(){
        // 这样生成的对象不是同步的,最后生成的hashcode不是同步的
        try{
            if(singleton2 == null){
                Thread.sleep(3000);
                singleton2 = new Singleton2();
            }
        }
        catch (InterruptedException e){
            e.printStackTrace();
        }
        return  singleton2;
    }
}
